package com.unipay.hosp.api;

import com.unipay.common.result.Result;
import com.unipay.hosp.service.DepartmentService;
import com.unipay.hosp.service.HospitalService;
import com.unipay.hosp.service.HospitalSetService;
import com.unipay.hosp.service.ScheduleService;
import com.unipay.model.hosp.Hospital;
import com.unipay.model.hosp.Schedule;
import com.unipay.vo.hosp.DepartmentVo;
import com.unipay.vo.hosp.HospitalQueryVo;
import com.unipay.vo.hosp.ScheduleOrderVo;
import com.unipay.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Project: yitong_parent
 * @Author: C.yu
 * @Time: 2023-04-29 21:43:35
 * @Desc: TODO
 */
@Api(tags = "用户系统Hosp接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private HospitalSetService hospitalSetService;

    @ApiOperation("获取Hosp分页列表")
    @GetMapping("findHospList/{page}/{limit}")      // Get方法：参数用params，没有RequestBdy
    public Result findHospList(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitalPage = hospitalService.selPageHospptal(page, limit, hospitalQueryVo);
        return Result.ok(hospitalPage);
    }

    @ApiOperation("根据Hosp名称关键字搜索医院列表")
    @GetMapping("/findByHosname/{hosname}")
    public Result findByHosname(@PathVariable String hosname) {
        List<Hospital> hospitalList = hospitalService.findByHosname(hosname);
        return Result.ok(hospitalList);
    }

    @ApiOperation("根据hoscode获取科室列表")
    @GetMapping("/getDepByHoscode/{hoscode}")
    public Result getDepByHoscode(@PathVariable String hoscode) {
        List<DepartmentVo> deptTree = departmentService.findDeptTree(hoscode);
        return Result.ok(deptTree);
    }

    @ApiOperation("根据hoscode获取医院预约挂号详情")
    @GetMapping("/getHospDetail/{hoscode}")
    public Result getHospDetail(@PathVariable String hoscode) {
        Map<String, Object> hospDetailMap = hospitalService.getHospDetail(hoscode);
        return Result.ok(hospDetailMap);
    }

    @ApiOperation("获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode
    ) {
        Map<String, Object> map = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return Result.ok(map);
    }

    @ApiOperation(value = "获取该workDate排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {
        List<Schedule> detailScheduleList = scheduleService.getScheduleDetail(hoscode, depcode, workDate);
        return Result.ok(detailScheduleList);
    }

    @ApiOperation("根据排班ID获取schedule数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(
            @ApiParam(name = "scheduleId", value = "排班ID", required = true)
            @PathVariable String scheduleId
    ) {
        Schedule schedule = scheduleService.getByID(scheduleId);
        return Result.ok(schedule);
    }

    @ApiOperation("根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班ID", required = true)
            @PathVariable("scheduleId") String scheduleId
    ) {
        ScheduleOrderVo scheduleOrderVo = scheduleService.getScheduleOrderVo(scheduleId);
        return scheduleOrderVo;
    }

    @ApiOperation("根据hoscode获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable("hoscode") String hoscode
            ) {
        // String sign = hospitalSetService.getSignKey(hoscode);
        return hospitalSetService.getSignInfoVo(hoscode);
    }
}
